Skip to content

[Bugfix #1853] porch: save failed check output to a log, print its last lines - #1964

Open
waleedkadous wants to merge 12 commits into
mainfrom
builder/bugfix-1853
Open

waleedkadous wants to merge 12 commits into
mainfrom
builder/bugfix-1853

Conversation

@waleedkadous

@waleedkadous waleedkadous commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1853

Problem

When a porch check failed, porch done (and porch check / porch approve) printed the first five lines of the check's stderr and nothing else. For the tests check those five lines are npm's Unknown env config warnings, so the failing test was never named. Nothing was written to disk, so a retry that passed erased the evidence.

Reproduced through porch's own runner with one failing vitest test under the real npm test -- --exclude='**/e2e/**' <file> command: porch printed five npm warn lines and .... The test's name was in stderr's FAIL <file> > <suite> > <test> block, the last ~18 lines, and in stdout's × <test> line, which porch never printed.

Root cause

packages/codev/src/commands/porch/checks.ts:

  • runCheck put stdout in output and stderr in error. formatCheckResults printed only error.split('\n').slice(0, 5) and never output.
  • The timeout result carried neither stream, so a timed-out check lost all its output.
  • No output was saved anywhere.

Fix

Scope follows the architect's comment on the issue: persist and tail. The commit-adjacent timing is out of scope; it is explained by #1956.

  • Transcript. runCheck keeps stdout and stderr as one transcript, in the order porch read them, on every failure path: non-zero exit, timeout, spawn error. Each stream enters it a whole line at a time, so the two pipes never splice mid-line. error now holds only the reason (Exit code 1, Killed by SIGKILL, Timed out after …).
  • Log file. With a log target, runPhaseChecks saves each failed shell check's full output to codev/projects/<id>-<name>/checks/<timestamp>-<phase>-<check>.log. The file has a header (check, phase, command, cwd, result, duration) and then the transcript. porch check, porch done and porch approve all pass the target. porch.checks overrides and timeouts go through the same path.
  • Bounded. The newest 20 logs per project are kept. Timestamp-first names sort oldest to newest. The file just written is never pruned.
  • Out of git. The directory carries its own .gitignore (*). Adopters' .gitignore has no rule for codev/projects/ (see the note in consult/tree-tripwire.ts), so a repo-level rule here would not have covered them. Porch only ever git adds status.yaml, and afx cleanup --keep-ignored keeps codev/projects/** by default.
  • Terminal. The output keeps the reason, then shows the last 30 lines of the transcript and Full output: <path>. If the log cannot be written, porch prints Full output could not be saved: <why> and does not throw, so the failure is still shown.
  • Docs. The porch skill (all four copies, still byte-identical) says where the log is. The shipped skill hashes are regenerated for that edit.

Testing

  • New bugfix-1853-check-output.test.ts has 9 tests. Eight of them fail against the old checks.ts; the ninth, "a passing check writes nothing", is a guard.
    • A check that prints 50 warnings before its failure shows the failure line, the summary and the log path, and not the first warning.
    • The log holds the whole of stdout and stderr, plus the header.
    • A passing check writes nothing.
    • A check killed at its timeout saves and shows what it printed.
    • A porch.checks override that fails is saved.
    • With 25 old logs present, only the newest 20 are kept, and git status in a fresh repo shows none of them.
    • The log just written survives pruning when 20 later-named logs exist.
    • A stderr line split across writes, with a stdout line between them, stays whole.
    • A log that cannot be written is reported, and the failure is still printed.
  • checks.test.ts: two tests updated for the new error meaning and the tail-first truncation.
  • Local full suite, run by porch. VITEST_MAX_WORKERS=3 node packages/codev/bin/porch.js done bugfix-1853, using this branch's porch: build passed (19.5s), tests passed (142.6s), 165s wall, peak 1-min load 15. An earlier run with the installed porch failed on skill-refresh.test.ts, because I had edited the porch skill without regenerating its hash; that is fixed in b06deb4. That run showed the bug itself: the old porch printed five npm warn lines and saved nothing. The failure was named from vitest's results cache. A probe through porch's own runCheck confirmed the cap reaches vitest: with VITEST_MAX_WORKERS=3, at most 3 workers; without it, 6.
  • Targeted. checks, porch: per-check timeout_ms in protocol.json (checks die at the fixed 5-minute cap) #1814 timeout, porch done truncates failing check output; the failing test is never named #1853, skill-refresh, done-verification, porch approve plan-approval fails with 'Plan not found' when plan is in builder worktree #676 approve, advance-uses-workspace-root, gate-auto-open, governance-sweep. Also tsc --noEmit, a type-check of the edited tests, and pnpm build.
  • End-to-end with the built CLI in a scratch workspace: porch check and porch done print the failure line, the summary and the log path, and porch done exits 1. The checks/ directory holds the logs and its .gitignore, and git status is clean.
  • End-to-end with a real failing vitest test under npm test: the tail shows × the named failing test, the FAIL … > the named failing test block, the summary and the log path.
  • Windows (on-demand, suites=true):

CMAP

  • claude: APPROVE. Five non-blocking notes.
    • Fixed: stream splicing, the write-only stderr accumulator, and the prune that could delete the new log (5a67e58, with tests in 32fd783).
    • Not changed: secrets in a failed transcript (the logs are gitignored, local to the worktree, removed by afx cleanup); seven positional arguments on runPhaseChecks (a refactor, outside a bugfix); no size cap on a log (the in-memory copy is as before; the log count is bounded).
  • codex: REQUEST_CHANGES, on commit-message format only: the chore(porch): … commits lack the [Bugfix #1853] prefix. Not changed. Those are porch's own state commits from writeStateAndCommit, which every porch project carries (87 of main's last 200 commits). Renaming them would mean rewriting and force-pushing porch-owned history. codex found no code, test or security issue.

… lines

A failed check printed the first five lines of its stderr and nothing else.
For the tests check those lines are npm config warnings, so the failing test
was never named, and nothing was kept: a passing retry erased the evidence.

- runCheck keeps stdout and stderr as one transcript, in the order porch read
  them, on every failure path: exit code, timeout, spawn error. `error` now
  says only why the check failed (exit code, signal, timeout).
- porch check/done/approve save a failed shell check's full output to
  codev/projects/<id>-<name>/checks/<timestamp>-<phase>-<check>.log, keep the
  newest 20, and ignore the directory from inside (adopters' .gitignore has no
  rule for codev/projects/). A log that cannot be written is reported, not
  thrown, so the failure itself is still printed.
- formatCheckResults prints the reason, the last 30 lines of the transcript,
  and the log path.
- porch skill (all four copies) says where the log is.
…ed in full

A check that prints 50 warnings before its failure shows the failure, the
summary and the log path; the log holds all of stdout and stderr; a passing
check writes nothing; a timed-out check and a porch.checks override are saved
too; only the newest 20 logs are kept and git does not see them; an unwritable
log is reported while the failure is still printed. Six of the seven fail
against the old checks.ts. checks.test.ts follows `error` (now the reason, with
stderr in the transcript) and the tail-first truncation.
…st written

From CMAP (claude, non-blocking):
- Chunks from the stdout and stderr pipes are not line-aligned, so a stdout
  chunk could land mid-line in a stderr one. Each stream now enters the
  transcript a whole line at a time; an unterminated last line is added at
  the end.
- The stderr accumulator was written and never read once `error` became the
  reason. Dropped.
- The newest-20 prune counted the file just written, so with 20 later-named
  logs present (clock skew, a copied log) porch printed a path it had just
  deleted. The new file is now excluded from pruning.
…urvives pruning

Both fail against the previous checks.ts.
@waleedkadous
waleedkadous marked this pull request as ready for review November 24, 2026 01:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

porch done truncates failing check output; the failing test is never named

1 participant